﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sugar.Enties;
using Seating.vo;
namespace Seating
{
    public partial class Library_Close_Strategy_Form : Form
    {
        public Library_Close_Strategy_Form()
        {
            InitializeComponent();
        }

        private void Library_Close_Strategy_Form_Load(object sender, EventArgs e)
        {
            // 查询图书室列表
            Tb_LibraryManager manager = new Tb_LibraryManager();
            List<Tb_Library> list = manager.GetList();
            foreach (var item in list)
            {
                comboBox_library.Items.Add(new ItemVo() { Text = item.Name, Value = item.LibraryId });

            }

        }

        private void button_query_Click(object sender, EventArgs e)
        {
            doQuery();
        }

        private void doQuery()
        {
            Tb_LibraryCloseStrategyManager manager = new Tb_LibraryCloseStrategyManager();
            ItemVo item = (ItemVo)comboBox_library.SelectedItem;
            if (item == null)
            {
                MessageBox.Show("请选择正确数据");
                return;
            }
            dataGridView_library.Columns.Clear();

            List<Tb_LibraryCloseStrategy> list = manager.getByLibraryId(item.Value);

            dataGridView_library.DataSource = list;

            dataGridView_library.ReadOnly = true;

                addDeleteBtn();

           
        }

        private void addDeleteBtn()
        {
            // 添加按钮
            DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
            btnDelete.Name = "btnDelete";
            btnDelete.HeaderText = "";
            btnDelete.DefaultCellStyle.NullValue = "删除";
            this.dataGridView_library.Columns.Add(btnDelete);

            // 

        }

        private void button_add_Click(object sender, EventArgs e)
        {
            Form form = new Library_Close_Add_Form();
            DialogResult result = form.ShowDialog();
            if (result == DialogResult.OK)
            {
                doQuery();
            }

        }

        private void dataGridView_library_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            //点击button按钮事件
            if (e.RowIndex < 0)
            {
                return;
            }
            Tb_LibraryCloseStrategy item = (Tb_LibraryCloseStrategy)this.dataGridView_library.CurrentRow.DataBoundItem;

            switch (this.dataGridView_library.Columns[e.ColumnIndex].Name)
            {
                case "btnDelete":
                    new Tb_LibraryCloseStrategyManager().Delete(item);
                    MessageBox.Show("删除成功");
                    doQuery();
                    break;


            }
        }
    }
}
